package com.example.demo.vo;

public class RestResponse {

    private int code;

    private String message;


    public enum ResponseType{
        SUCCESS, ERROR, UN_AUTH, UN_LOGIN, LOGOUT
    }

    public RestResponse(ResponseType responseType) {
        switch (responseType) {
            case SUCCESS:
                this.code = 200;
                this.message = "成功";
                break;
            case ERROR:
                this.code = 500;
                this.message = "错误";
                break;
            case UN_AUTH:
                this.code = 501;
                this.message = "没有权限";
                break;
            case LOGOUT:
                this.code = 502;
                this.message = "已登出";
                break;
            case UN_LOGIN:
                this.code = 503;
                this.message = "没有登录";
                break;
            default:
                this.code = 400;
        }
    }

    public RestResponse(RuntimeException e) {
        this.code = 500;
        this.message = e.getMessage();
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static class DataResponse<T> extends RestResponse {

        private T data;
        private T data1;
        private int totalcount;

        public DataResponse(ResponseType responseType, T data) {
            super(responseType);
            this.data = data;

        }
        public DataResponse(ResponseType responseType, T data, T data1) {
            super(responseType);
            this.data = data;
            this.data1=data1;

        }

        public DataResponse(ResponseType responseType, T data, int totalcount) {
            super(responseType);
            this.data = data;
            this.totalcount=totalcount;

        }

        public int getTotalcount() {
            return totalcount;
        }

        public void setTotalcount(int totalcount) {
            this.totalcount = totalcount;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }

        public T getData1() {
            return data1;
        }

        public void setData1(T data1) {
            this.data1 = data1;
        }
    }
}
